package com.example.multitenancy01.controller;

import com.example.multitenancy01.entity.User;
import com.example.multitenancy01.mapper.UserMapper;
import com.example.multitenancy01.util.JudgeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;


/**
 *  测试
 */
@RestController
@RequestMapping("/userController")
@Slf4j
public class UserController {

    @Autowired
    private UserMapper userMapper;


    /**
     *  测试新增用户
     *  127.0.0.1:8080/userController/insert
     */
    @RequestMapping("/insert")
    public void insert(@RequestBody User user){
        int insert = userMapper.insert(user); // 新增数据
        user = userMapper.selectById(user.getId());
        log.info("插入数据:{}", user);
        new JudgeUtil().judgeTenantId(user);
    }

    /**
     * 查询数据
     * 127.0.0.1:8080/userController/selectList
     */
    @RequestMapping("/selectList")
    public void selectList() {
        List<User> users = userMapper.selectList(null);
        users.forEach((user) -> {
            log.info("查询数据{}", user);
            new JudgeUtil().judgeTenantId(user);
        });
    }
}
